<style lang="scss" type="stylesheet/scss" scoped>
.as-card {
  background: white;
  border-radius: 4px;
  margin-bottom: 40px;
  .slot {
    &.is-disabled {
      position: relative;
      .mask {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1;
        background: rgba(0, 0, 0, 0.7);
        display: flex;
        justify-content: center;
        align-items: center;
        color: white;
        font-size: 14px;
      }
    }
    padding: 22px 22px 12px 22px;
  }
  .triggler {
    height: 50px;
    border-top: 1px solid #ebebeb;
    line-height: 50px;
    color: #999;
    text-align: center;
    transition: color 0.2s ease;
    cursor: pointer;
    &:hover {
      color: mix(white, #1368dd, 20%);
    }
  }
  .as-card__header {
    line-height: 1.5;
    padding: 20px;
    color: #333;
    border-bottom: 1px solid mix(white, #ebebeb, 50%);
  }
  .as-code__warpper {
    overflow-x: auto;
    overflow-y: hidden;
    background: #282c34;
    // background: mix(white, #1368dd, 90%);

    .as-code {
      transform-origin: top;
    }
  }
}
</style>

<template>
  <div class="as-card">
    <div class="as-card__header">{{title}}</div>
    <div class="slot"
         :class="[{'is-disabled':disabled}]">
      <div class="mask"
           v-if="disabled">
        [ * 该组件暂不适配移动端，请在 PC 端查看 ]
      </div>
      <slot></slot>
    </div>
    <div class="as-code__warpper"
         :style="{transition,height:height+'px'}">
      <as-code :text="text"
               lang="html"
               ref="asCode"
               inner></as-code>
    </div>
    <div class="triggler"
         @click="trigglerCardVisible">
      <i :class="`el-icon-caret-${height!==constHeight?'bottom':'top'}`"></i>
      {{height!==constHeight?'展开':'关闭'}}代码
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  name: "AsCard",
  props: ["text", "title", "disabled"],
  data() {
    return {
      visible: true,
      transition: "",
      constHeight: null,
      height: "auto"
    };
  },
  methods: {
    trigglerCardVisible() {
      this.height = this.height === this.constHeight ? 0 : this.constHeight;
    }
  },
  mounted() {
    this.constHeight =
      this.$refs.asCode.$el.getBoundingClientRect().height
      //  - 48;

    // this.visible = false;
    this.transition = "height 0.4s ease";
    this.height = 0;
  }
};
</script>
